package com.game.modular.game.match.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.game.comment.util.JwtUtils;
import com.game.modular.game.match.domain.PvpMatchEnd;
import com.game.modular.game.match.service.PvpMatchEndServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.game.comment.core.ResponseResult;

import java.util.List;


/**
 * pvp对局信息(PvpMatchEnd)表服务控制层
 *
 * @author cxy
 * @since 2024-09-09 11:57:21
 */
@Api(tags = "pvp对局信息(PvpMatchEnd)") 
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/pvpMatchEnd")
public class PvpMatchEndController {
    @Resource
    private PvpMatchEndServiceImpl pvpMatchEndService;
    
    @ApiOperation("获取pvp对局信息列表")
    @PostMapping("/list")
    public ResponseResult<List<PvpMatchEnd>> list(@RequestHeader String token) {
        Long playerId = JwtUtils.getPlayerId(token);
        LambdaQueryWrapper<PvpMatchEnd> pvpMatchEndLambdaQueryWrapper = new LambdaQueryWrapper<>();
        pvpMatchEndLambdaQueryWrapper.eq(PvpMatchEnd::getPlayerId, playerId);
        pvpMatchEndLambdaQueryWrapper.orderByDesc(PvpMatchEnd::getMatchId);
        // 最多50
        pvpMatchEndLambdaQueryWrapper.last("limit 50");
        return ResponseResult.success(pvpMatchEndService.list());
    }

    @ApiOperation("最新一场的pvp结算信息(经验|积分)")
    @PostMapping("/select")
    public ResponseResult<PvpMatchEnd> select(@RequestHeader String token) {
        Long playerId = JwtUtils.getPlayerId(token);
        LambdaQueryWrapper<PvpMatchEnd> pvpMatchEndLambdaQueryWrapper = new LambdaQueryWrapper<>();
        pvpMatchEndLambdaQueryWrapper.eq(PvpMatchEnd::getPlayerId, playerId);
        pvpMatchEndLambdaQueryWrapper.orderByDesc(PvpMatchEnd::getMatchId);
        pvpMatchEndLambdaQueryWrapper.last("limit 1");
        return ResponseResult.success(pvpMatchEndService.getOne(pvpMatchEndLambdaQueryWrapper));
    }
}
